package helloworld.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class MulticastReciever implements Runnable {
	private String message = null;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@Override
	public void run() {
		MulticastSocket multicastSocket = null;
		try {
			multicastSocket = new MulticastSocket(8089);
			multicastSocket.joinGroup(InetAddress.getByName("224.0.0.0"));
			byte[] bytesToReceice = new byte[65535];
			DatagramPacket datagramPacket = new DatagramPacket(bytesToReceice,
					bytesToReceice.length);
			multicastSocket.receive(datagramPacket);
			this.message = new String(datagramPacket.getData());
			multicastSocket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}